<template>
  <view class="myheader ">
	  <view class="header" :style="{ position: headerPosition,top:headerTop,opacity: afterHeaderOpacity }">
		  <!-- logo -->
		  <view class="icon-btn">
		  	<view class="icon left_icon" @tap="toIndex">
		  	    <image mode="widthFix" :src="home_logo"></image>
		  	</view>
		  </view>
		
		  <view  class="logo" >
		  	<image mode="widthFix" class="logo-img" :src="jswb_logo"></image>
		  </view>
		  <!-- 右侧图标按钮 -->
		  <view class="icon-btn">
		  	<view class="icon" @tap="toCenter">
				<image class="icon-img" :src="headimg" ></image>
			</view>
		  </view>
		 <hr>
	  </view>
	<view class="place"></view>
  </view>
</template>

<script>
	export default{
		data() {
			return{
				afterHeaderOpacity: 1,//不透明度
				headerPosition: 'fixed',
				headerTop:null,
				backpage:'../login/login?backpage=' + '../pages/index/index',
				islogin:'false',
				headimg:'../../static/img/copoun/person_icon.png',
				home_logo:'../../static/img/copoun/home_logo.png',
				jswb_logo:'../../static/img/copoun/jswb_logo_login.png'
			}
		},
		mounted() {
			let token=uni.getStorageSync("token_h5")
			console.log(this.$route.path)
			if(token){
				 this.headimg='../../static/img/copoun/head_img.png';
			 }
			else{
				  this.headimg='../../static/img/copoun/person_icon.png';
			}
			if(this.$route.path=="/pages/Index/index"||this.$route.path=="/pages/login/login"||this.$route.path=="/"){
				this.home_logo='../../static/img/copoun/home_logo.png'
				
			}
			else{
				this.home_logo='../../static/img/copoun/back_logo.png'
			}
			//隐藏logo切换
			// if(this.$route.path=="/pages/login/login"||this.$route.path=="/pages/login/register"){
			// 	this.jswb_logo='../../static/img/copoun/jswb_logo_login.png'
				
			// }
			// else{
			// 	this.jswb_logo='../../static/img/copoun/jswb_logo.png'
			// }
		},
		methods:{
			toCenter(){
				let token=uni.getStorageSync("token_h5")
				if(token){
					 this.headimg='../../static/img/copoun/head_img.png';
					uni.navigateTo({
						url: '../user/user'
					});
				}
				else{
					this.headimg='../../static/img/copoun/person_icon.png';
					uni.navigateTo({
						url: '../login/login'
					});
				}
			},toIndex(){
				console.log(this.$route.path)
				const pages = getCurrentPages();
				console.log("当前页数"+pages.length)
				 if(this.$route.path=="/pages/Index/index"||this.$route.path=="/pages/login/login"||this.$route.path=="/"||this.$route.path=="/pages/copoun/copoun"){
				 uni.navigateTo({
				 	url: '../Index/index'
				 });
				 	
				 }
				 else{
					 if(pages.length==1)
					 {
						 uni.navigateTo({
						 	url: '../Index/index'
						 });
					 }
					 else{
						 uni.navigateBack({
						 	delta: 1
						 });
					 }
				 	
				 }
			},
			changeimg(){
				let token=uni.getStorageSync("token_h5")
				console.log(token)
				if(token){
					 this.headimg='../../static/img/copoun/head_img.png';
				 }
				else{
					  this.headimg='../../static/img/copoun/person_icon.png';
				}
				
			}
		}
	}
</script>

<style lang="scss">
	.header {
		width: 92%;
		padding: 0 4%;
		height: 100upx;
		display: flex;
		align-items: center;
		position: fixed;
		top: 0;
		z-index: 10;
		background-color: #fff;
	    hr{
			    display: block;
			    width: 92%;
			    position: absolute;
			    top: 100upx;
			    background: #D8D8D8;
			    height: 1upx;
			    border: none;
		}
		/*  #ifdef  APP-PLUS  */
		top: var(--status-bar-height);
		/*  #endif  */
	    .logo{
			margin-top: 5px;
			width: 100%;
			text-align: center;
			.logo-img{
				width: 260upx;
				//height: 66upx;
			}
			
		}
		.zhanwei{
			width: 60upx;
		}
		.icon-btn {
			width: 50upx;
			height: 50upx;
			flex-shrink: 0;
			display: flex;
			.icon {
				width: 50upx;
				height: 50upx;
				display: flex;
				justify-content: flex-end;
				align-items: center;
				font-size: 42upx;
				image{
					width: 90%;
					height: 90%;
				}
			}
			.left_icon{
					height: 60upx;
			}
		}
	}
	.place {
		background-color: #ffffff;
		height: 100upx;
		/*  #ifdef  APP-PLUS  */
		margin-top: var(--status-bar-height);
		/*  #endif  */
	}
</style>
